/**
 * Created by Francis.LW on 2017/10/20.
 *
 * 工单服务接口
 */
import {postRequest, getRequest} from '@/common/request'
import {urls} from './url'

const electronicWorksheetsApi = urls.electronicWorksheets

function listElectronicWorksheets(param, page, pageSize, success, complete) {
  postRequest(electronicWorksheetsApi.listElectronicWorksheets + '?currentpage=' + page + '&pagesize=' + pageSize, {}, param, success, complete)
}

function listOperationWorkOrder(param, page, pageSize, success, complete) {
  postRequest(electronicWorksheetsApi.listOperationWorkOrder + '?currentpage=' + page + '&pagesize=' + pageSize, {}, param, success, complete)
}

function generateWorkOrderForm(param, success, complete) {
  postRequest(electronicWorksheetsApi.generateWorkOrderForm, {}, param, success, complete)
}

function workOrderOperationView(id, success, complete) {
  getRequest(electronicWorksheetsApi.workOrderOperationView + id, {}, success, complete)
}

function initCarCondition(id, success, complete) {
  getRequest(electronicWorksheetsApi.initCarCondition + id, {}, success, complete)
}

function updateWorkOrderKm(id, param, success, complete) {
  postRequest(electronicWorksheetsApi.updateWorkOrderKm + id, {}, param, success, complete)
}

function countWorkOrder(orderFlag, success, complete) {
  getRequest(electronicWorksheetsApi.countWorkOrder, {orderFlag: orderFlag}, success, complete)
}

function workOrderView(id, success, complete) {
  getRequest(electronicWorksheetsApi.workOrderView + id, {}, success, complete)
}

function removeElectronicWorksheets(ids, success, complete) {
  postRequest(electronicWorksheetsApi.removeElectronicWorksheets, {}, ids, success, complete)
}

function removeOperationElectronicWorksheets(ids, success, complete) {
  postRequest(electronicWorksheetsApi.removeOperationElectronicWorksheets, {}, ids, success, complete)
}

function deleteSingleElectronicWorksheets(id, success, complete) {
  let ids = []
  ids.push(id)
  removeElectronicWorksheets(ids, success, complete)
}

function deleteSingleOperationElectronicWorksheets(id, success, complete) {
  let ids = []
  ids.push(id)
  removeOperationElectronicWorksheets(ids, success, complete)
}

export default {
  initCarCondition,
  generateWorkOrderForm,
  listOperationWorkOrder,
  listElectronicWorksheets,
  workOrderView,
  countWorkOrder,
  workOrderOperationView,
  removeElectronicWorksheets,
  removeOperationElectronicWorksheets,
  deleteSingleElectronicWorksheets,
  deleteSingleOperationElectronicWorksheets,
  updateWorkOrderKm
}
